/*
 * Copyright 2022 The Open Islands Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.openislands.oi.dao.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.gitee.sunchenbin.mybatis.actable.annotation.*;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import org.apache.ibatis.type.BooleanTypeHandler;
import org.apache.ibatis.type.EnumTypeHandler;
import org.openislands.oi.config.typehandler.JsonTypeHandler;
import org.openislands.oi.constant.NodeState;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

@TableComment("worker node info")
@TableName(value = "t_node", autoResultMap = true)
public class NodeDO extends BaseDO implements Serializable {
    @Unique
    @TableField(value = "f_node_id")
    private String nodeId;

    @Column(isNull = false, defaultValue = "")
    @TableField("f_node_name")
    private String nodeName;

    @IsNotNull
    @TableField("f_owner")
    private String owner;

    @ColumnType(MySqlTypeConstant.TEXT)
    @TableField("f_public_key")
    private String publicKey;

    @ColumnType(MySqlTypeConstant.TEXT)
    @TableField("f_private_key")
    private String privateKey;

    @ColumnType(MySqlTypeConstant.TEXT)
    @TableField(value = "f_node_info", typeHandler = JsonTypeHandler.StringMap.class)
    private Map<String, Object> nodeInfo;

    @TableField("f_description")
    private String description;

    @Index
    @Column(isNull = false, type = MySqlTypeConstant.VARCHAR, length = 31)
    @TableField(value = "f_state", typeHandler = EnumTypeHandler.class)
    private NodeState state;

    @Index
    @Column(isNull = false, defaultValue = "1")
    @TableField(value = "f_enabled", typeHandler = BooleanTypeHandler.class)
    private Boolean enabled;

    @ColumnType(MySqlTypeConstant.TIMESTAMP)
    @TableField("f_join_time")
    private Date joinTime;

    @Column(defaultValue = "0")
    @TableField("f_call_total")
    private Long callTotal;

    @Column(length = 20)
    @TableField("f_call_strategy")
    private String callStrategy;

    @ColumnType(MySqlTypeConstant.TIMESTAMP)
    @TableField("f_last_heartbeat_time")
    private Date lastHeartbeatTime;

    @ColumnType(MySqlTypeConstant.TIMESTAMP)
    @TableField("f_last_call_time")
    private Date lastCallTime;

    public String getNodeId() {
        return nodeId;
    }

    public void setNodeId(String nodeId) {
        this.nodeId = nodeId;
    }

    public String getNodeName() {
        return nodeName;
    }

    public void setNodeName(String nodeName) {
        this.nodeName = nodeName;
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    public String getPublicKey() {
        return publicKey;
    }

    public void setPublicKey(String publicKey) {
        this.publicKey = publicKey;
    }

    public String getPrivateKey() {
        return privateKey;
    }

    public void setPrivateKey(String privateKey) {
        this.privateKey = privateKey;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public NodeState getState() {
        return state;
    }

    public void setState(NodeState state) {
        this.state = state;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public Map<String, Object> getNodeInfo() {
        return nodeInfo;
    }

    public void setNodeInfo(Map<String, Object> nodeInfo) {
        this.nodeInfo = nodeInfo;
    }

    public Date getJoinTime() {
        return joinTime;
    }

    public void setJoinTime(Date joinTime) {
        this.joinTime = joinTime;
    }

    public Long getCallTotal() {
        return callTotal;
    }

    public void setCallTotal(Long callTotal) {
        this.callTotal = callTotal;
    }

    public String getCallStrategy() {
        return callStrategy;
    }

    public void setCallStrategy(String callStrategy) {
        this.callStrategy = callStrategy;
    }

    public Date getLastHeartbeatTime() {
        return lastHeartbeatTime;
    }

    public void setLastHeartbeatTime(Date lastHeartbeatTime) {
        this.lastHeartbeatTime = lastHeartbeatTime;
    }

    public Date getLastCallTime() {
        return lastCallTime;
    }

    public void setLastCallTime(Date lastCallTime) {
        this.lastCallTime = lastCallTime;
    }
}